package com.hongtai.mysql_json_study.controller;

import com.alibaba.fastjson.JSONObject;
import com.hongtai.mysql_json_study.service.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class Controller {

    @Autowired
    Service service;
    @RequestMapping("")
    public String index(){
        return "nice";
    }

    @RequestMapping("add1")
    public String add1(){
        return "result:"+service.add1();
    }
    @RequestMapping("add2")
    public String add2(){
        return "result:"+service.add2();
    }

    @RequestMapping("findip")
    public String findIpById(){
        return "result:"+ service.findIpById();
    }
    @RequestMapping("findkeys")
    public String findKeysById(){
        String keys = service.findKeysById();
        System.out.println("第一个属性是："+JSONObject.parseArray(keys).get(0));
        return "result:"+ JSONObject.parseArray(keys);
    }

    @RequestMapping("deletekey")
    public String deleteKey(){
        return "result:"+ service.deleteKey();
    }
    @RequestMapping("addkey")
    public String addKey(){
        return "result:"+ service.changeKey();
    }
    @RequestMapping("findbyid")
    public String findById(){
        return "result:"+ JSONObject.toJSONString(service.findById());
    }
    @RequestMapping("findall")
    public String findAll(){
        return "result:"+ JSONObject.toJSONString(service.findAll());
    }




}
